<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">

<title>format_specifications - RDoc Documentation</title>


<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>

<script src="./js/jquery-3.2.0.min.js"></script>

<script src="./js/vue.min.js"></script>
<script src="./js/js.cookie.min.js"></script>

<link href="./css/fonts.css" rel="stylesheet">
<link id='rdoccss' href="./css/rdoc.css" rel="stylesheet">
<link href="./css/carbon17.css" rel="stylesheet">

<script type="text/javascript">
  var rdoc_rel_prefix = "./";
  var index_rel_prefix = "./";
  var darkModeCsseHref = "./css/rdoc-dm.css"
  var defaultModeCssHref = "./css/rdoc.css"
  // var cssDarkmode = Cookies.get('darkmode');
  
  if( Cookies.get("darkmode") == "true") {
	$('#rdoccss').attr("href", darkModeCsseHref);
}

//  https://cssdeck.com/blog/simple-jquery-stylesheet-switcher/

document.write('<style type="text/css">body{display:none}</style>');

</script>


</head>
<body id="top" role="document" class="file">
  <!-- this is page.html -->
  <div id='actionbar' >
    <div class='wrapper mdiv'>
      <ul class='grids g0'></ul>
    </div> 
    <!-- VERSION HEADER for 3.3.0-preview2 NOT FOUND -->
  </div> <!-- end action bar -->


 <div class='wrapper hdiv'>

 


<nav id='vapp' role="navigation">
  <div id="project-navigation">
    <div id="home-section" role="region" title="Quick navigation" class="nav-section">
  <h2><a href="./index.html" rel="home">Home</a></h2>

  <div id="table-of-contents-navigation"  >
    <a href="./table_of_contents.html#pages">Pages</a>
    <a href="./table_of_contents.html#classes">Classes</a>
    <a href="./table_of_contents.html#methods">Methods</a>
  </div>
</div>

    <div id="search-section" role="search" class="project-section initially-hidden">
  <form action="#" method="get" accept-charset="utf-8">
    <div id="search-field-wrapper">
      <input id="search-field" role="combobox" aria-label="Search"
             aria-autocomplete="list" aria-controls="search-results"
             type="text" name="search" placeholder="Search" spellcheck="false"
             title="Type to search, Up and Down to navigate, Enter to load">
    </div>

    <ul id="search-results" aria-label="Search Results"
        aria-busy="false" aria-expanded="false"
        aria-atomic="false" class="initially-hidden"></ul>
  </form>
</div>

  </div>

  
<div class="nav-section">
  <h3>Table of Contents</h3>

  <ul class="link-list" role="directory">
    <li><a href="#label-Format+Specifications">Format Specifications</a>
    <li><a href="#label-Type+Specifiers">Type Specifiers</a>
    <li><a href="#label-Integer+Type+Specifiers">Integer Type Specifiers</a>
    <li><a href="#label-Floating-Point+Type+Specifiers">Floating-Point Type Specifiers</a>
    <li><a href="#label-Other+Type+Specifiers">Other Type Specifiers</a>
    <li><a href="#label-Flags">Flags</a>
    <li><a href="#label-27+-27+Flag"><code>&#39; &#39;</code> Flag</a>
    <li><a href="#label-27-23-27+Flag"><code>&#39;#&#39;</code> Flag</a>
    <li><a href="#label-27-2B-27+Flag"><code>&#39;+&#39;</code> Flag</a>
    <li><a href="#label-27--27+Flag"><code>&#39;-&#39;</code> Flag</a>
    <li><a href="#label-270-27+Flag"><code>&#39;0&#39;</code> Flag</a>
    <li><a href="#label-27-2A-27+Flag"><code>&#39;*&#39;</code> Flag</a>
    <li><a href="#label-27n-24-27+Flag"><code>&#39;n$&#39;</code> Flag</a>
    <li><a href="#label-Width+Specifier">Width Specifier</a>
    <li><a href="#label-Precision+Specifier">Precision Specifier</a>
    <li><a href="#label-Type+Specifier+Details+and+Examples">Type Specifier Details and Examples</a>
    <li><a href="#label-Specifiers+a+and+A">Specifiers <code>a</code> and <code>A</code></a>
    <li><a href="#label-Specifiers+b+and+B">Specifiers <code>b</code> and <code>B</code></a>
    <li><a href="#label-Specifier+c">Specifier <code>c</code></a>
    <li><a href="#label-Specifier+d">Specifier <code>d</code></a>
    <li><a href="#label-Specifiers+e+and+E">Specifiers <code>e</code> and <code>E</code></a>
    <li><a href="#label-Specifier+f">Specifier <code>f</code></a>
    <li><a href="#label-Specifiers+g+and+G">Specifiers <code>g</code> and <code>G</code></a>
    <li><a href="#label-Specifier+o">Specifier <code>o</code></a>
    <li><a href="#label-Specifier+p">Specifier <code>p</code></a>
    <li><a href="#label-Specifier+s">Specifier <code>s</code></a>
    <li><a href="#label-Specifiers+x+and+X">Specifiers <code>x</code> and <code>X</code></a>
    <li><a href="#label-Specifier+-25">Specifier <code>%</code></a>
    <li><a href="#label-Reference+by+Name">Reference by Name</a>
  </ul>
</div>

  <button id='toggleThing' @click="toggleNav()" >Show/hide navigation</button>

  <div id="project-metadata">
   <div :class="isOpen ? 'block' : 'hidden' " id='toggleMe'>
    
<div id="fileindex-section" class="nav-section">
  <h3>Pages</h3>

  <ul class="link-list">
    <li><a href="./NEWS/NEWS-1_8_7.html">NEWS-1.8.7</a>
    <li><a href="./NEWS/NEWS-1_9_1.html">NEWS-1.9.1</a>
    <li><a href="./NEWS/NEWS-1_9_2.html">NEWS-1.9.2</a>
    <li><a href="./NEWS/NEWS-1_9_3.html">NEWS-1.9.3</a>
    <li><a href="./NEWS/NEWS-2_0_0.html">NEWS-2.0.0</a>
    <li><a href="./NEWS/NEWS-2_1_0.html">NEWS-2.1.0</a>
    <li><a href="./NEWS/NEWS-2_2_0.html">NEWS-2.2.0</a>
    <li><a href="./NEWS/NEWS-2_3_0.html">NEWS-2.3.0</a>
    <li><a href="./NEWS/NEWS-2_4_0.html">NEWS-2.4.0</a>
    <li><a href="./NEWS/NEWS-2_5_0.html">NEWS-2.5.0</a>
    <li><a href="./NEWS/NEWS-2_6_0.html">NEWS-2.6.0</a>
    <li><a href="./NEWS/NEWS-2_7_0.html">NEWS-2.7.0</a>
    <li><a href="./NEWS/NEWS-3_0_0_md.html">NEWS-3.0.0</a>
    <li><a href="./NEWS/NEWS-3_1_0_md.html">NEWS-3.1.0</a>
    <li><a href="./NEWS/NEWS-3_2_0_md.html">NEWS-3.2.0</a>
    <li><a href="./bsearch_rdoc.html">bsearch</a>
    <li><a href="./bug_triaging_rdoc.html">bug_triaging</a>
    <li><a href="./case_mapping_rdoc.html">case_mapping</a>
    <li><a href="./character_selectors_rdoc.html">character_selectors</a>
    <li><a href="./command_injection_rdoc.html">command_injection</a>
    <li><a href="./contributing_md.html">contributing</a>
    <li><a href="./contributing/building_ruby_md.html">building_ruby</a>
    <li><a href="./contributing/documentation_guide_md.html">documentation_guide</a>
    <li><a href="./contributing/glossary_md.html">glossary</a>
    <li><a href="./contributing/making_changes_to_ruby_md.html">making_changes_to_ruby</a>
    <li><a href="./contributing/making_changes_to_stdlibs_md.html">making_changes_to_stdlibs</a>
    <li><a href="./contributing/reporting_issues_md.html">reporting_issues</a>
    <li><a href="./contributing/testing_ruby_md.html">testing_ruby</a>
    <li><a href="./dig_methods_rdoc.html">dig_methods</a>
    <li><a href="./distribution_md.html">distribution</a>
    <li><a href="./dtrace_probes_rdoc.html">dtrace_probes</a>
    <li><a href="./encodings_rdoc.html">encodings</a>
    <li><a href="./extension_ja_rdoc.html">extension.ja</a>
    <li><a href="./extension_rdoc.html">extension</a>
    <li><a href="./fiber_md.html">fiber</a>
    <li><a href="./format_specifications_rdoc.html">format_specifications</a>
    <li><a href="./globals_rdoc.html">globals</a>
    <li><a href="./implicit_conversion_rdoc.html">implicit_conversion</a>
    <li><a href="./keywords_rdoc.html">keywords</a>
    <li><a href="./maintainers_md.html">maintainers</a>
    <li><a href="./marshal_rdoc.html">marshal</a>
    <li><a href="./memory_view_md.html">memory_view</a>
    <li><a href="./optparse/argument_converters_rdoc.html">argument_converters</a>
    <li><a href="./optparse/creates_option_rdoc.html">creates_option</a>
    <li><a href="./optparse/option_params_rdoc.html">option_params</a>
    <li><a href="./optparse/tutorial_rdoc.html">tutorial</a>
    <li><a href="./packed_data_rdoc.html">packed_data</a>
    <li><a href="./ractor_md.html">ractor</a>
    <li><a href="./regexp_rdoc.html">regexp</a>
    <li><a href="./regexp/methods_rdoc.html">methods</a>
    <li><a href="./regexp/unicode_properties_rdoc.html">unicode_properties</a>
    <li><a href="./ruby_3_3_0_preview2/COPYING.html">COPYING</a>
    <li><a href="./ruby_3_3_0_preview2/COPYING_ja.html">COPYING.ja</a>
    <li><a href="./ruby_3_3_0_preview2/LEGAL.html">LEGAL</a>
    <li><a href="./ruby_3_3_0_preview2/NEWS_md.html">NEWS</a>
    <li><a href="./ruby_3_3_0_preview2/README_ja_md.html">README.ja</a>
    <li><a href="./ruby_3_3_0_preview2/README_md.html">README</a>
    <li><a href="./security_rdoc.html">security</a>
    <li><a href="./signals_rdoc.html">signals</a>
    <li><a href="./standard_library_rdoc.html">standard_library</a>
    <li><a href="./strftime_formatting_rdoc.html">strftime_formatting</a>
    <li><a href="./syntax_rdoc.html">syntax</a>
    <li><a href="./syntax/assignment_rdoc.html">assignment</a>
    <li><a href="./syntax/calling_methods_rdoc.html">calling_methods</a>
    <li><a href="./syntax/comments_rdoc.html">comments</a>
    <li><a href="./syntax/control_expressions_rdoc.html">control_expressions</a>
    <li><a href="./syntax/exceptions_rdoc.html">exceptions</a>
    <li><a href="./syntax/literals_rdoc.html">literals</a>
    <li><a href="./syntax/methods_rdoc.html">methods</a>
    <li><a href="./syntax/miscellaneous_rdoc.html">miscellaneous</a>
    <li><a href="./syntax/modules_and_classes_rdoc.html">modules_and_classes</a>
    <li><a href="./syntax/pattern_matching_rdoc.html">pattern_matching</a>
    <li><a href="./syntax/precedence_rdoc.html">precedence</a>
    <li><a href="./syntax/refinements_rdoc.html">refinements</a>
    <li><a href="./timezones_rdoc.html">timezones</a>
    <li><a href="./windows_md.html">windows</a>
    <li><a href="./yjit/yjit_md.html">yjit</a>
    <li><a href="./yjit/yjit_hacking_md.html">yjit_hacking</a>
  </ul>
</div>

   </div>
  </div>
</nav>


<!--  carbon ads here -->

<div id='extraz'>
  <div class='adzbox-index'  >
   
  </div>
 </div>         


<main role="main" aria-label="Page format_specifications.rdoc">

<h2 id="label-Format+Specifications">Format Specifications<span><a href="#label-Format+Specifications">&para;</a> <a href="#top">&uarr;</a></span></h2>

<p>Several Ruby core classes have instance method <code>printf</code> or <code>sprintf</code>:</p>
<ul><li>
<p><a href="ARGF.html#method-i-printf"><code>ARGF#printf</code></a></p>
</li><li>
<p><a href="IO.html#method-i-printf"><code>IO#printf</code></a></p>
</li><li>
<p><a href="Kernel.html#method-i-printf"><code>Kernel#printf</code></a></p>
</li><li>
<p><a href="Kernel.html#method-i-sprintf"><code>Kernel#sprintf</code></a></p>
</li></ul>

<p>Each of these methods takes:</p>
<ul><li>
<p>Argument <code>format_string</code>, which has zero or more embedded <em>format</em> <em>specifications</em> (see below).</p>
</li><li>
<p>Arguments <code>*arguments</code>, which are zero or more objects to be formatted.</p>
</li></ul>

<p>Each of these methods prints or returns the string resulting from replacing each format specification embedded in <code>format_string</code> with a string form of the corresponding argument among <code>arguments</code>.</p>

<p>A simple example:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;Name: %s; value: %d&#39;</span>, <span class="ruby-string">&#39;Foo&#39;</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; &quot;Name: Foo; value: 0&quot;</span>
</pre>

<p>A format specification has the form:</p>

<pre>%[flags][width][.precision]type</pre>

<p>It consists of:</p>
<ul><li>
<p>A leading percent character.</p>
</li><li>
<p>Zero or more <em>flags</em> (each is a character).</p>
</li><li>
<p>An optional <em>width</em> <em>specifier</em> (an integer).</p>
</li><li>
<p>An optional <em>precision</em> <em>specifier</em> (a period followed by a non-negative integer).</p>
</li><li>
<p>A <em>type</em> <em>specifier</em> (a character).</p>
</li></ul>

<p>Except for the leading percent character, the only required part is the type specifier, so we begin with that.</p>

<h3 id="label-Type+Specifiers">Type Specifiers<span><a href="#label-Type+Specifiers">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>This section provides a brief explanation of each type specifier. The links lead to the details and examples.</p>

<h4 id="label-Integer+Type+Specifiers">Integer Type Specifiers<span><a href="#label-Integer+Type+Specifiers">&para;</a> <a href="#top">&uarr;</a></span></h4>
<ul><li>
<p><code>b</code> or <code>B</code>: Format <code>argument</code> as a binary integer. See <a href="format_specifications_rdoc.html#label-Specifiers+b+and+B">Specifiers b and B</a>.</p>
</li><li>
<p><code>d</code>, <code>i</code>, or <code>u</code> (all are identical): Format <code>argument</code> as a decimal integer. See <a href="format_specifications_rdoc.html#label-Specifier+d">Specifier d</a>.</p>
</li><li>
<p><code>o</code>: Format <code>argument</code> as an octal integer. See <a href="format_specifications_rdoc.html#label-Specifier+o">Specifier o</a>.</p>
</li><li>
<p><code>x</code> or <code>X</code>: Format <code>argument</code> as a hexadecimal integer. See <a href="format_specifications_rdoc.html#label-Specifiers+x+and+X">Specifiers x and X</a>.</p>
</li></ul>

<h4 id="label-Floating-Point+Type+Specifiers">Floating-Point Type Specifiers<span><a href="#label-Floating-Point+Type+Specifiers">&para;</a> <a href="#top">&uarr;</a></span></h4>
<ul><li>
<p><code>a</code> or <code>A</code>: Format <code>argument</code> as hexadecimal floating-point number. See <a href="format_specifications_rdoc.html#label-Specifiers+a+and+A">Specifiers a and A</a>.</p>
</li><li>
<p><code>e</code> or <code>E</code>: Format <code>argument</code> in scientific notation. See <a href="format_specifications_rdoc.html#label-Specifiers+e+and+E">Specifiers e and E</a>.</p>
</li><li>
<p><code>f</code>: Format <code>argument</code> as a decimal floating-point number. See <a href="format_specifications_rdoc.html#label-Specifier+f">Specifier f</a>.</p>
</li><li>
<p><code>g</code> or <code>G</code>: Format <code>argument</code> in a “general” format. See <a href="format_specifications_rdoc.html#label-Specifiers+g+and+G">Specifiers g and G</a>.</p>
</li></ul>

<h4 id="label-Other+Type+Specifiers">Other Type Specifiers<span><a href="#label-Other+Type+Specifiers">&para;</a> <a href="#top">&uarr;</a></span></h4>
<ul><li>
<p><code>c</code>: Format <code>argument</code> as a character. See <a href="format_specifications_rdoc.html#label-Specifier+c">Specifier c</a>.</p>
</li><li>
<p><code>p</code>: Format <code>argument</code> as a string via <code>argument.inspect</code>. See <a href="format_specifications_rdoc.html#label-Specifier+p">Specifier p</a>.</p>
</li><li>
<p><code>s</code>: Format <code>argument</code> as a string via <code>argument.to_s</code>. See <a href="format_specifications_rdoc.html#label-Specifier+s">Specifier s</a>.</p>
</li><li>
<p><code>%</code>: Format <code>argument</code> (<code>&#39;%&#39;</code>) as a single percent character. See <a href="format_specifications_rdoc.html#label-Specifier+-25">Specifier %</a>.</p>
</li></ul>

<h3 id="label-Flags">Flags<span><a href="#label-Flags">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>The effect of a flag may vary greatly among type specifiers. These remarks are general in nature. See <a href="format_specifications_rdoc.html#label-Type+Specifier+Details+and+Examples">type-specific details</a>.</p>

<p>Multiple flags may be given with single type specifier; order does not matter.</p>

<h4 id="label-27+-27+Flag"><code>&#39; &#39;</code> Flag<span><a href="#label-27+-27+Flag">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Insert a space before a non-negative number:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%d&#39;</span>, <span class="ruby-value">10</span>)  <span class="ruby-comment"># =&gt; &quot;10&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;% d&#39;</span>, <span class="ruby-value">10</span>) <span class="ruby-comment"># =&gt; &quot; 10&quot;</span>
</pre>

<p>Insert a minus sign for negative value:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%d&#39;</span>, <span class="ruby-value">-10</span>)  <span class="ruby-comment"># =&gt; &quot;-10&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;% d&#39;</span>, <span class="ruby-value">-10</span>) <span class="ruby-comment"># =&gt; &quot;-10&quot;</span>
</pre>

<h4 id="label-27-23-27+Flag"><code>&#39;#&#39;</code> Flag<span><a href="#label-27-23-27+Flag">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Use an alternate format; varies among types:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%x&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;64&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#x&#39;</span>, <span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; &quot;0x64&quot;</span>
</pre>

<h4 id="label-27-2B-27+Flag"><code>&#39;+&#39;</code> Flag<span><a href="#label-27-2B-27+Flag">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Add a leading plus sign for a non-negative number:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%x&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;64&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%+x&#39;</span>, <span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; &quot;+64&quot;</span>
</pre>

<h4 id="label-27--27+Flag"><code>&#39;-&#39;</code> Flag<span><a href="#label-27--27+Flag">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Left justify the value in its field:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%6d&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;   100&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%-6d&#39;</span>, <span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; &quot;100   &quot;</span>
</pre>

<h4 id="label-270-27+Flag"><code>&#39;0&#39;</code> Flag<span><a href="#label-270-27+Flag">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Left-pad with zeros instead of spaces:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%6d&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;   100&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%06d&#39;</span>, <span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; &quot;000100&quot;</span>
</pre>

<h4 id="label-27-2A-27+Flag"><code>&#39;*&#39;</code> Flag<span><a href="#label-27-2A-27+Flag">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Use the next argument as the field width:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%d&#39;</span>, <span class="ruby-value">20</span>, <span class="ruby-value">14</span>)  <span class="ruby-comment"># =&gt; &quot;20&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%*d&#39;</span>, <span class="ruby-value">20</span>, <span class="ruby-value">14</span>) <span class="ruby-comment"># =&gt; &quot;                  14&quot;</span>
</pre>

<h4 id="label-27n-24-27+Flag"><code>&#39;n$&#39;</code> Flag<span><a href="#label-27n-24-27+Flag">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format the (1-based) <code>n</code>th argument into this field:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;%s %s&quot;</span>, <span class="ruby-string">&#39;world&#39;</span>, <span class="ruby-string">&#39;hello&#39;</span>)     <span class="ruby-comment"># =&gt; &quot;world hello&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;%2$s %1$s&quot;</span>, <span class="ruby-string">&#39;world&#39;</span>, <span class="ruby-string">&#39;hello&#39;</span>) <span class="ruby-comment"># =&gt; &quot;hello world&quot;</span>
</pre>

<h3 id="label-Width+Specifier">Width Specifier<span><a href="#label-Width+Specifier">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>In general, a width specifier determines the minimum width (in characters) of the formatted field:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%10d&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;       100&quot;</span>

<span class="ruby-comment"># Left-justify if negative.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%-10d&#39;</span>, <span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; &quot;100       &quot;</span>

<span class="ruby-comment"># Ignore if too small.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%1d&#39;</span>, <span class="ruby-value">100</span>)   <span class="ruby-comment"># =&gt; &quot;100&quot;</span>
</pre>

<h3 id="label-Precision+Specifier">Precision Specifier<span><a href="#label-Precision+Specifier">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>A precision specifier is a decimal point followed by zero or more decimal digits.</p>

<p>For integer type specifiers, the precision specifies the minimum number of digits to be written. If the precision is shorter than the integer, the result is padded with leading zeros. There is no modification or truncation of the result if the integer is longer than the precision:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.3d&#39;</span>, <span class="ruby-value">1</span>)    <span class="ruby-comment"># =&gt; &quot;001&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.3d&#39;</span>, <span class="ruby-value">1000</span>) <span class="ruby-comment"># =&gt; &quot;1000&quot;</span>

<span class="ruby-comment"># If the precision is 0 and the value is 0, nothing is written</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.d&#39;</span>, <span class="ruby-value">0</span>)  <span class="ruby-comment"># =&gt; &quot;&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.0d&#39;</span>, <span class="ruby-value">0</span>) <span class="ruby-comment"># =&gt; &quot;&quot;</span>
</pre>

<p>For the <code>a</code>/<code>A</code>, <code>e</code>/<code>E</code>, <code>f</code>/<code>F</code> specifiers, the precision specifies the number of digits after the decimal point to be written:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.2f&#39;</span>, <span class="ruby-value">3.14159</span>)  <span class="ruby-comment"># =&gt; &quot;3.14&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.10f&#39;</span>, <span class="ruby-value">3.14159</span>) <span class="ruby-comment"># =&gt; &quot;3.1415900000&quot;</span>

<span class="ruby-comment"># With no precision specifier, defaults to 6-digit precision.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%f&#39;</span>, <span class="ruby-value">3.14159</span>)    <span class="ruby-comment"># =&gt; &quot;3.141590&quot;</span>
</pre>

<p>For the <code>g</code>/<code>G</code> specifiers, the precision specifies the number of significant digits to be written:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.2g&#39;</span>, <span class="ruby-value">123.45</span>)  <span class="ruby-comment"># =&gt; &quot;1.2e+02&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.3g&#39;</span>, <span class="ruby-value">123.45</span>)  <span class="ruby-comment"># =&gt; &quot;123&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.10g&#39;</span>, <span class="ruby-value">123.45</span>) <span class="ruby-comment"># =&gt;  &quot;123.45&quot;</span>

<span class="ruby-comment"># With no precision specifier, defaults to 6 significant digits.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%g&#39;</span>, <span class="ruby-value">123.456789</span>) <span class="ruby-comment"># =&gt; &quot;123.457&quot;</span>
</pre>

<p>For the <code>s</code>, <code>p</code> specifiers, the precision specifies the number of characters to write:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%s&#39;</span>, <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>)    <span class="ruby-comment"># =&gt; &quot;2022-05-04 11:59:16 -0400&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%.10s&#39;</span>, <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>) <span class="ruby-comment"># =&gt; &quot;2022-05-04&quot;</span>
</pre>

<h3 id="label-Type+Specifier+Details+and+Examples">Type Specifier Details and Examples<span><a href="#label-Type+Specifier+Details+and+Examples">&para;</a> <a href="#top">&uarr;</a></span></h3>

<h4 id="label-Specifiers+a+and+A">Specifiers <code>a</code> and <code>A</code><span><a href="#label-Specifiers+a+and+A">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as hexadecimal floating-point number:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%a&#39;</span>, <span class="ruby-value">3.14159</span>)   <span class="ruby-comment"># =&gt; &quot;0x1.921f9f01b866ep+1&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%a&#39;</span>, <span class="ruby-value">-3.14159</span>)  <span class="ruby-comment"># =&gt; &quot;-0x1.921f9f01b866ep+1&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%a&#39;</span>, <span class="ruby-value">4096</span>)      <span class="ruby-comment"># =&gt; &quot;0x1p+12&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%a&#39;</span>, <span class="ruby-value">-4096</span>)     <span class="ruby-comment"># =&gt; &quot;-0x1p+12&quot;</span>

<span class="ruby-comment"># Capital &#39;A&#39; means that alphabetical characters are printed in upper case.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%A&#39;</span>, <span class="ruby-value">4096</span>)      <span class="ruby-comment"># =&gt; &quot;0X1P+12&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%A&#39;</span>, <span class="ruby-value">-4096</span>)     <span class="ruby-comment"># =&gt; &quot;-0X1P+12&quot;</span>
</pre>

<h4 id="label-Specifiers+b+and+B">Specifiers <code>b</code> and <code>B</code><span><a href="#label-Specifiers+b+and+B">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>The two specifiers <code>b</code> and <code>B</code> behave identically except when flag <code>&#39;#&#39;</code>+ is used.</p>

<p>Format <code>argument</code> as a binary integer:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%b&#39;</span>, <span class="ruby-value">1</span>)  <span class="ruby-comment"># =&gt; &quot;1&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%b&#39;</span>, <span class="ruby-value">4</span>)  <span class="ruby-comment"># =&gt; &quot;100&quot;</span>

<span class="ruby-comment"># Prefix &#39;..&#39; for negative value.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%b&#39;</span>, <span class="ruby-value">-4</span>) <span class="ruby-comment"># =&gt; &quot;..100&quot;</span>

<span class="ruby-comment"># Alternate format.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#b&#39;</span>, <span class="ruby-value">4</span>)  <span class="ruby-comment"># =&gt; &quot;0b100&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#B&#39;</span>, <span class="ruby-value">4</span>)  <span class="ruby-comment"># =&gt; &quot;0B100&quot;</span>
</pre>

<h4 id="label-Specifier+c">Specifier <code>c</code><span><a href="#label-Specifier+c">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as a single character:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%c&#39;</span>, <span class="ruby-string">&#39;A&#39;</span>) <span class="ruby-comment"># =&gt; &quot;A&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%c&#39;</span>, <span class="ruby-value">65</span>)  <span class="ruby-comment"># =&gt; &quot;A&quot;</span>
</pre>

<h4 id="label-Specifier+d">Specifier <code>d</code><span><a href="#label-Specifier+d">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as a decimal integer:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%d&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;100&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%d&#39;</span>, <span class="ruby-value">-100</span>) <span class="ruby-comment"># =&gt; &quot;-100&quot;</span>
</pre>

<p>Flag <code>&#39;#&#39;</code> does not apply.</p>

<h4 id="label-Specifiers+e+and+E">Specifiers <code>e</code> and <code>E</code><span><a href="#label-Specifiers+e+and+E">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> in <a href="https://en.wikipedia.org/wiki/Scientific_notation">scientific notation</a>:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%e&#39;</span>, <span class="ruby-value">3.14159</span>)  <span class="ruby-comment"># =&gt; &quot;3.141590e+00&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%E&#39;</span>, <span class="ruby-value">-3.14159</span>) <span class="ruby-comment"># =&gt; &quot;-3.141590E+00&quot;</span>
</pre>

<h4 id="label-Specifier+f">Specifier <code>f</code><span><a href="#label-Specifier+f">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as a floating-point number:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%f&#39;</span>, <span class="ruby-value">3.14159</span>)  <span class="ruby-comment"># =&gt; &quot;3.141590&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%f&#39;</span>, <span class="ruby-value">-3.14159</span>) <span class="ruby-comment"># =&gt; &quot;-3.141590&quot;</span>
</pre>

<p>Flag <code>&#39;#&#39;</code> does not apply.</p>

<h4 id="label-Specifiers+g+and+G">Specifiers <code>g</code> and <code>G</code><span><a href="#label-Specifiers+g+and+G">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> using exponential form (<code>e</code>/<code>E</code> specifier) if the exponent is less than -4 or greater than or equal to the precision. Otherwise format <code>argument</code> using floating-point form (<code>f</code> specifier):</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%g&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;100&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%g&#39;</span>, <span class="ruby-value">100.0</span>)  <span class="ruby-comment"># =&gt; &quot;100&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%g&#39;</span>, <span class="ruby-value">3.14159</span>)  <span class="ruby-comment"># =&gt; &quot;3.14159&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%g&#39;</span>, <span class="ruby-value">100000000000</span>)  <span class="ruby-comment"># =&gt; &quot;1e+11&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%g&#39;</span>, <span class="ruby-value">0.000000000001</span>)  <span class="ruby-comment"># =&gt; &quot;1e-12&quot;</span>

<span class="ruby-comment"># Capital &#39;G&#39; means use capital &#39;E&#39;.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%G&#39;</span>, <span class="ruby-value">100000000000</span>)  <span class="ruby-comment"># =&gt; &quot;1E+11&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%G&#39;</span>, <span class="ruby-value">0.000000000001</span>)  <span class="ruby-comment"># =&gt; &quot;1E-12&quot;</span>

<span class="ruby-comment"># Alternate format.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#g&#39;</span>, <span class="ruby-value">100000000000</span>)  <span class="ruby-comment"># =&gt; &quot;1.00000e+11&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#g&#39;</span>, <span class="ruby-value">0.000000000001</span>)  <span class="ruby-comment"># =&gt; &quot;1.00000e-12&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#G&#39;</span>, <span class="ruby-value">100000000000</span>)  <span class="ruby-comment"># =&gt; &quot;1.00000E+11&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#G&#39;</span>, <span class="ruby-value">0.000000000001</span>)  <span class="ruby-comment"># =&gt; &quot;1.00000E-12&quot;</span>
</pre>

<h4 id="label-Specifier+o">Specifier <code>o</code><span><a href="#label-Specifier+o">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as an octal integer. If <code>argument</code> is negative, it will be formatted as a two’s complement prefixed with <code>..7</code>:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%o&#39;</span>, <span class="ruby-value">16</span>)   <span class="ruby-comment"># =&gt; &quot;20&quot;</span>

<span class="ruby-comment"># Prefix &#39;..7&#39; for negative value.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%o&#39;</span>, <span class="ruby-value">-16</span>)  <span class="ruby-comment"># =&gt; &quot;..760&quot;</span>

<span class="ruby-comment"># Prefix zero for alternate format if positive.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#o&#39;</span>, <span class="ruby-value">16</span>)  <span class="ruby-comment"># =&gt; &quot;020&quot;</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#o&#39;</span>, <span class="ruby-value">-16</span>) <span class="ruby-comment"># =&gt; &quot;..760&quot;</span>
</pre>

<h4 id="label-Specifier+p">Specifier <code>p</code><span><a href="#label-Specifier+p">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as a string via <code>argument.inspect</code>:</p>

<pre class="ruby"><span class="ruby-identifier">t</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%p&#39;</span>, <span class="ruby-identifier">t</span>)   <span class="ruby-comment"># =&gt; &quot;2022-05-01 13:42:07.1645683 -0500&quot;</span>
</pre>

<h4 id="label-Specifier+s">Specifier <code>s</code><span><a href="#label-Specifier+s">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as a string via <code>argument.to_s</code>:</p>

<pre class="ruby"><span class="ruby-identifier">t</span> = <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%s&#39;</span>, <span class="ruby-identifier">t</span>) <span class="ruby-comment"># =&gt; &quot;2022-05-01 13:42:07 -0500&quot;</span>
</pre>

<p>Flag <code>&#39;#&#39;</code> does not apply.</p>

<h4 id="label-Specifiers+x+and+X">Specifiers <code>x</code> and <code>X</code><span><a href="#label-Specifiers+x+and+X">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> as a hexadecimal integer. If <code>argument</code> is negative, it will be formatted as a two’s complement prefixed with <code>..f</code>:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%x&#39;</span>, <span class="ruby-value">100</span>)   <span class="ruby-comment"># =&gt; &quot;64&quot;</span>

<span class="ruby-comment"># Prefix &#39;..f&#39; for negative value.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%x&#39;</span>, <span class="ruby-value">-100</span>)  <span class="ruby-comment"># =&gt; &quot;..f9c&quot;</span>

<span class="ruby-comment"># Use alternate format.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#x&#39;</span>, <span class="ruby-value">100</span>)  <span class="ruby-comment"># =&gt; &quot;0x64&quot;</span>

<span class="ruby-comment"># Alternate format for negative value.</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%#x&#39;</span>, <span class="ruby-value">-100</span>) <span class="ruby-comment"># =&gt; &quot;0x..f9c&quot;</span>
</pre>

<h4 id="label-Specifier+-25">Specifier <code>%</code><span><a href="#label-Specifier+-25">&para;</a> <a href="#top">&uarr;</a></span></h4>

<p>Format <code>argument</code> (<code>&#39;%&#39;</code>) as a single percent character:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&#39;%d %%&#39;</span>, <span class="ruby-value">100</span>) <span class="ruby-comment"># =&gt; &quot;100 %&quot;</span>
</pre>

<p>Flags do not apply.</p>

<h3 id="label-Reference+by+Name">Reference by Name<span><a href="#label-Reference+by+Name">&para;</a> <a href="#top">&uarr;</a></span></h3>

<p>For more complex formatting, Ruby supports a reference by name. %&lt;name&gt;s style uses format style, but %{name} style doesn’t.</p>

<p>Examples:</p>

<pre class="ruby"><span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;%&lt;foo&gt;d : %&lt;bar&gt;f&quot;</span>, { <span class="ruby-value">:foo</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">1</span>, <span class="ruby-value">:bar</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">2</span> }) <span class="ruby-comment"># =&gt; 1 : 2.000000</span>
<span class="ruby-identifier">sprintf</span>(<span class="ruby-string">&quot;%{foo}f&quot;</span>, { <span class="ruby-value">:foo</span> <span class="ruby-operator">=&gt;</span> <span class="ruby-value">1</span> })                      <span class="ruby-comment"># =&gt; &quot;1f&quot;</span>
</pre>

</main>

</div>  <!--  class='wrapper hdiv' -->


<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a></p>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.4.0.</p>
<p>Based on <a href="https://github.com/ged/darkfish/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.</p>

  
    <p><p><a href="https://ruby-doc.org">Ruby-doc.org</a> is a service of <a href="https://jamesbritt.com">James Britt</a> and <a href="https://neurogami.com">Neurogami</a>, purveyors of fine <a href='https://jamesbritt.bandcamp.com/'>dance noise</a></p>
</p>
  
  </footer>

<script type="text/javascript">


  let ads  = $("#carbonads-container").children().detach();


  function swapMode() {
    var cookieName = 'darkmode';
    var cssDarkmode = Cookies.get(cookieName);
    console.log("***** swapMode! " + cssDarkmode + " *****");


    if (cssDarkmode == "true") {
      console.log("We have dark mode, set the css to light ...");
      $('#rdoccss').attr("href", defaultModeCssHref);
      $('#cssSelect').text("Dark mode");
      cssDarkmode = "false";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    } else {
      console.log("We not have dark mode, set the css to dark ...");
      $('#rdoccss').attr("href", darkModeCsseHref);
      $('#cssSelect').text("Light mode");
      cssDarkmode = "true";
      console.log("swapMode! Now set cookie to " + cssDarkmode);
      Cookies.set(cookieName, cssDarkmode);

    }

    console.log("  --------------- ");
  }


const vueCssApp = new Vue({
el: '#menubar',
data: {
isDark: false
},
methods: {
toggleClass: function(event){
this.isDark = !this.isDark;
}
}
})

const vueApp = new Vue({
el: '#vapp',
data: { 
isOpen: true
},

mounted() {
this.handleResize();
this.manage_mob_classes();
window.addEventListener('resize', this.handleResize)
//this.isOpen !=  (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},
destroyed() {
window.removeEventListener('resize', this.handleResize)
},
created() {
//manage_mob_classes();
},

methods : {
isMobile() {
  return (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent));
},

  handleResize() {
    if (!this.isMobile()) {
      this.isOpen = window.innerWidth > 800;
    }
  },

  manage_mob_classes() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      $("nav").addClass("mob_nav");
      $("main").addClass("mob_main");
      $("#extraz").addClass("mob_extraz");
      $("#carbonads-container").addClass("mob_carbonads-container");
      this.isOpen  = false;
    } else {
      $("nav").removeClass("mob_nav") 
        $("main").removeClass("mob_main");
      $("#extraz").removeClass("mob_extraz");
      $("#carbonads-container").removeClass("mob_carbonads-container");
      this.isOpen  = true;
    }
  },

  toggleNav() {
    this.isOpen =! this.isOpen ;
    // alert("Toggle nav!");
    console.log("toggleNav() click: " + this.isOpen );
  }
}
})

$("#carbonads-container").append(ads);


$(function() {

    var darkmode = Cookies.get("darkmode");
    console.log("Document ready: " + darkmode);

    if ( darkmode  == "true" ) {
      $('#cssSelect').text("Light mode");
    } else {
      $('#cssSelect').text("Dark mode");
     }

    $('body').css('display','block');
    });

</script>

    
  </body> 
</html>

